home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / nxyplot / Source / pvDrag.m < prev    next >
Text File  |  1993-09-22  |  2KB  |  85 lines

  1. #import "Plot.h"
  2. #import "PlotView.h"
  3. #import <appkit/drag.h>
  4. #import <appkit/Pasteboard.h>
  5. #import <bsd/strings.h>        // for declaration of strchr
  6.  
  7. /*
  8.  * Dragging code for PlotView.
  9.  */
  10.  
  11. @implementation PlotView(Drag)
  12.  
  13.  
  14. /* Method to search through Pasteboard types lists (from Draw Example). */
  15.  
  16. BOOL IncludesType(const NXAtom *types, NXAtom type)
  17. {
  18.     if (types) {
  19.       while (*types) {
  20.     if (*types++ == type) return YES;
  21.       }
  22.     }
  23.     return NO;
  24. }
  25.  
  26.  
  27. /*
  28.  * Just see if there is a file there we can copy.  Code taken from
  29.  * the Draw Example in NextDeveloper/Examples.
  30.  */
  31. - (NXDragOperation)draggingEntered:(id <NXDraggingInfo>)sender
  32. {
  33.   Pasteboard *pboard;
  34.   NXDragOperation sourceMask;
  35.  
  36.   sourceMask = [sender draggingSourceOperationMask];
  37.   pboard = [sender draggingPasteboard];
  38.  
  39.   if (sourceMask & NX_DragOperationCopy) {
  40.     if (IncludesType([pboard types], NXFilenamePboardType)) { // why?
  41.       return NX_DragOperationCopy;
  42.     }
  43.   }
  44.  
  45.   return NX_DragOperationNone;
  46. }
  47.  
  48.  
  49. /*
  50.  * Try to plot any file(s) that have been dragged onto us.
  51.  */
  52. - (BOOL)performDragOperation:(id <NXDraggingInfo>)sender
  53. {
  54.   Pasteboard *pboard;
  55.   char     *stringPosition, *filename, *data;
  56.   int    length;
  57.  
  58.   pboard = [sender draggingPasteboard];
  59.  
  60.   if (IncludesType([pboard types], NXFilenamePboardType)) {
  61.     [pboard readType:NXFilenamePboardType data:&data length:&length];
  62.     filename = data;
  63.     while (filename) {
  64.       stringPosition = strchr(filename, '\t'); // returns first tab or NULL
  65.       if (stringPosition) {
  66.     *stringPosition = '\0';
  67.       }
  68.       if (filename[strlen(filename)-1]=='Z' && filename[strlen(filename)-2]=='.') {
  69.     [plotParam handleCompressedFile:filename];
  70.       }
  71.       else {
  72.     [plotParam openFile:filename :filename];
  73.       }
  74.       filename = (stringPosition ? ++stringPosition : NULL);
  75.     }
  76.     [pboard deallocatePasteboardData:data length:length];
  77.     return YES;
  78.   }
  79.   else {
  80.     return NO;
  81.   }
  82. }
  83.  
  84. @end
  85.